Implement SpectrumSource::iter_chromatograms so TIC/BPC chromatograms reach mzML output#18
Open
Nabejo wants to merge 1 commit into
Open
Implement SpectrumSource::iter_chromatograms so TIC/BPC chromatograms reach mzML output#18Nabejo wants to merge 1 commit into
Nabejo wants to merge 1 commit into
Conversation
Override the trait default so total-ion-current and base-peak chromatograms reach mzML output via OpenMassSpecCore's <chromatogramList> writer. Both traces are aggregated from already-decoded MS1 spectra (TIC = summed scan intensities, BPC = per-scan base peak) with no new binary parsing, keeping them self-consistent with the emitted spectra. Runs without MS1 scans (e.g. QQQ MRM) emit nothing; SRM chromatograms are skipped because the Q1/Q3 windows they require are not decoded. Implements Sigilweaver#17. Claude-Session: https://claude.ai/code/session_01TLSifJpmaN7RvW3xi2uWgo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17
What this does
Overrides the
SpectrumSource::iter_chromatogramstrait default onReader(the previous fall-through to the empty default meant no chromatograms reached mzML output). It emits two run-level summary chromatograms:MS:1000235"total ion current chromatogram"MS:1000628"basepeak chromatogram"Both are aggregated from data OpenARaw already decodes: for each MS1 scan, TIC is the sum of the decoded intensities and BPC is the most intense point, computed via
SpectrumRecord::effective_tic()/effective_base_peak(). This does no new binary parsing, and keeps the traces self-consistent with the spectra actually emitted for the run. Retention time is already carried in seconds bySpectrumRecord, so it is only narrowed tof32forChromatogramRecord::time_sec.Only MS1 scans contribute, since that is what the two CV terms describe and mixing interleaved MS2 scans would produce a non-chromatographic, RT-duplicated trace. Runs with no MS1 scans (e.g. QQQ MRM acquisitions, which are all MS2) emit no summary chromatograms rather than a misleading empty-typed one.
SRM/MRM transition chromatograms are intentionally not produced. OpenARaw decodes only an opaque
mrm_channel_id, not the Q1/Q3 isolation windows an SRM chromatogram needs; recovering those would be new binary parsing rather than wiring up already-decoded data, which is out of scope here.No downstream change is needed: OpenMassSpecCore's mzML writer (1.2.0) already calls
iter_chromatogramsand emits<chromatogramList>, writingchromatogram_typeverbatim.Testing
reader.rs(syntheticSpectrumRecords, no corpus needed): TIC/BPC are emitted over MS1 scans only with the correct accessions and aggregated values; empty result when there are no MS1 scans; empty MS1 scans contribute aligned zero points.cargo test --all(45 pass),cargo clippy --all-targets -- -D warnings(clean),cargo fmt --all -- --check(clean). The corpus-gated conformance tests still pass.Note on the issue text
The filed issue text is a copy from another repo (it references "OpenTFRaw",
crates/opentfraw/...paths, and a per-scan TIC/base-peak decode that already exists there). In OpenARaw those fields are not decoded per scan - theScanRecordinraw/msscan.rscarries retention time, MS level, mass range and precursor fields, but not TIC or base-peak, anddocs/format/01-msscan.mdonly tentatively labels the stride-284 offset-36 value as "TIC or related intensity metric". Rather than decode an unconfirmed field (a guess, and new binary parsing), I grounded the fix in this repo's actual code and derived the traces from the already-decoded MS1 intensities. The intent matches the cited Waters precedent (Sigilweaver/OpenWRaw#9, 574fe09): map what can be confidently derived, skip the rest.https://claude.ai/code/session_01TLSifJpmaN7RvW3xi2uWgo